/*
 * ******************************************************************************
 *   Copyright (c) 2013-2014 Gabriele Mariotti.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *  *****************************************************************************
 */

package it.gmariotti.cardslib.demo.fragment.nativeview;

import it.gmariotti.cardslib.demo.ResourceTable;
import it.gmariotti.cardslib.demo.fragment.BaseMaterialFragment;
import it.gmariotti.cardslib.library.cards.topcolored.TopColoredCard;
import it.gmariotti.cardslib.library.view.CardView;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

/**
 * @author Gabriele Mariotti (gabri.mariotti@gmail.com)
 */
public class NativeTopColoredCardFragment extends BaseMaterialFragment {

    public static final int SIMULATED_REFRESH_LENGTH = 3000;

    @Override
    protected int getSubTitleHeaderResourceId() {
        return ResourceTable.String_header_title_subtitle_ex_topcolored;
    }

    @Override
    protected int getTitleHeaderResourceId() {
        return ResourceTable.String_header_title_group2;
    }

    @Override
    protected String getDocUrl() {
        return null;
    }

    @Override
    protected String getSourceUrl() {
        return "";
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_demo_fragment_native_topcolored);
        initCards();
    }

    private void initCards() {
        init_HalfColoredCard();
        init_BlackTopColoredCard();
    }


    /**
     * Builds a Material HalfColored Card
     */
    private void init_HalfColoredCard() {

        TopColoredCard card = TopColoredCard.with(this)
                .setColorResId(ResourceTable.Color_carddemo_halfcolored_color)
                .setTitleOverColor("22 mins to Ancona")
                .setSubTitleOverColor("Light traffic on SS16")
                .setupSubLayoutId(ResourceTable.Layout_carddemo_native_halfcolored_simple_title)
                .setupInnerElements(secondHalfView -> {
                    Text mSimpleTitleView = (Text) secondHalfView.findComponentById(ResourceTable.Id_carddemo_halfcolored_simple_title);
                    if (mSimpleTitleView != null) {
                        mSimpleTitleView.setText("It is just an example!");
                    }
                })
                .build();

        //Set card in the CardView
        CardView cardView = (CardView) this.findComponentById(ResourceTable.Id_carddemo_halfcolored);
        cardView.setCard(card);
    }

    /**
     * Builds a Material HalfColored Card
     */
    private void init_BlackTopColoredCard() {

        TopColoredCard card = TopColoredCard.with(this)
                .setColorResId(ResourceTable.Color_carddemo_blackcolored_color)
                .setTitleOverColor(ResourceTable.String_carddemo_match)
                .setupSubLayoutId(ResourceTable.Layout_carddemo_native_blackcolored_simple_title)
                .setupInnerElements(secondHalfView -> {
                    Text mSimpleTitleView = (Text) secondHalfView.findComponentById(ResourceTable.Id_carddemo_blackcolored_simple_title);
                    if (mSimpleTitleView != null) {
                        mSimpleTitleView.setText("It is just an example!");
                    }
                })
                .build();

        //Set card in the CardView
        CardView cardView = (CardView) this.findComponentById(ResourceTable.Id_carddemo_blackcolored);
        cardView.setCard(card);
    }
}
